//
//  MNDFinanceNavMoreView.m
//  miniwangdai2
//
//  Created by 谭伟 on 2017/3/31.
//  Copyright © 2017年 谭谭伟. All rights reserved.
//
#pragma mark -点击投资navigation显示更多


#import "MNDFinanceNavMoreView.h"
#import "UIImage+JKColor.h"

@interface MNDFinanceNavMoreView()

@property (strong,nonatomic) NSString *borrowType;
@property (strong,nonatomic) NSString *deadline;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *topButtons;

@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *bottomButtons;
@property (weak, nonatomic) IBOutlet UIStackView *topStackView;
@property (weak, nonatomic) IBOutlet UIStackView *bttomStackView;
@property (weak, nonatomic) IBOutlet UIButton *transferBtn;
@property (strong, nonatomic) UIButton *borrowTypeSelectButton;
@property (strong, nonatomic) UIButton *deadlineSelectButton;

@property (weak, nonatomic) IBOutlet UIButton *allKindButton;
@property (weak, nonatomic) IBOutlet UIButton *allDeadButton;

@end
//投资类型选择通知名
#define kFinanceSelect @"FinanceSelect"
typedef enum {
    
    //标的种类
    FinanceTypeKind = 100,//种类100
    FinanceTypeAllKinds,//全部种类
    FinanceTypeCarBussiness,//车商贷
    FinanceTypeCarProfit,//车盈贷
    FinanceTypeTranfer,//债权转让
    //标的期限
    FinanceTypeDate,//期限
    FinanceTypeAllDate,//全部期限
    FinanceTypeOneMonth,//一个月
    FinanceTypeTwoMonth,//两个月
    FinanceTypeOneYear//一年

}FinanceType;


@implementation MNDFinanceNavMoreView


// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    //默认进来高亮状态
    self.borrowTypeSelectButton = self.allKindButton;
    self.deadlineSelectButton = self.allDeadButton;
    self.borrowType = @"";
    self.deadline = @"";
    
    //遍历
    for (UIButton *button in self.topButtons) {
        
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_selected"] forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_default"] forState:UIControlStateHighlighted];
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_default"] forState:UIControlStateNormal];
        
        [button setTitleColor:kColorBlack forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        
//        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    }
    for (UIButton *button in self.bottomButtons) {
        
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_selected"] forState:UIControlStateSelected];
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_default"] forState:UIControlStateHighlighted];
        [button setBackgroundImage:[UIImage imageNamed:@"finance_filter_default"] forState:UIControlStateNormal];
        [button setTitleColor:kColorBlack forState:UIControlStateNormal];
        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        
//        [button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
    }
    
//    [self.borrowTypeSelectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//    [self.borrowTypeSelectButton setBackgroundImage:[UIImage imageNamed:@"finance_filter_selected"] forState:UIControlStateHighlighted];
//    
//    [self.deadlineSelectButton setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
//    [self.deadlineSelectButton setBackgroundImage:[UIImage imageNamed:@"finance_filter_selected"] forState:UIControlStateHighlighted];
    
    if (kScreenWidth <= 640) {
        [self.transferBtn setTitle:@" 债权转让 " forState:UIControlStateNormal];
        self.topStackView.spacing = 8.0;
        self.bttomStackView.spacing = 8.0;
        
    }
}

//点击不同的类型展示不同的数据
- (IBAction)selectFinanceType:(UIButton *)sender {
    
    if (sender.tag == FinanceTypeAllKinds || sender.tag == FinanceTypeCarBussiness || sender.tag == FinanceTypeCarProfit || sender.tag == FinanceTypeTranfer) {
        self.borrowTypeSelectButton.selected = NO;
        self.borrowTypeSelectButton = sender;
        sender.selected = YES;
    }else {
        self.deadlineSelectButton.selected = NO;
        self.deadlineSelectButton = sender;
        sender.selected = YES;
    }
    //种类,字典不能添加nil对象，所以初始化为空
  
    switch (sender.tag) {
        case FinanceTypeAllKinds://全部种类
            {
                self.borrowType = @"";
            }
            break;
        case FinanceTypeCarBussiness:
            
            {
                self.borrowType = @"1";
            }
            break;
        case FinanceTypeCarProfit:
            {
                self.borrowType = @"2";
            }
            break;
        case FinanceTypeTranfer:
            {
                self.borrowType = @"3";

            }
            break;
        case FinanceTypeAllDate:
            {
                self. deadline = @"";
                
            }
            break;
        case FinanceTypeOneMonth:
            {
                self.deadline = @"1";
            }
            break;
        case FinanceTypeTwoMonth:
            {
                self.deadline = @"2";
            }
            break;
        case FinanceTypeOneYear:
            {
                self.deadline = @"12";
            }
            break;
            
        default:
            break;
    }
    
    NSDictionary *userInfoDict = @{@"borrow_type":self.borrowType,@"deadline":self.deadline,@"perpage":@"0"};
    
    //发送通知
//    [[NSNotificationCenter defaultCenter] postNotificationName:kFinanceSelect object:self userInfo:userInfoDict];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"kFinanceListType" object:self userInfo:userInfoDict];
    
}

@end
